package com.lizhijun.service.impl;

import com.lizhijun.mapper.FinanceMapper;
import com.lizhijun.pojo.Employee;
import com.lizhijun.service.FinanceService;
import com.lizhijun.utils.MybatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("financeService")
public class FinanceServiceImpl implements FinanceService {

    private SqlSessionFactory sqlSessionFactory = MybatisUtil.getSqlSessionFactory();

    @Override
    public List<Employee> findAll() {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        FinanceMapper mapper = sqlSession.getMapper(FinanceMapper.class);
        List<Employee> employeeList = mapper.findAll();
        sqlSession.close();
        return employeeList;
    }

    @Override
    public void updateBonusAndDeduction(Employee employee) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        FinanceMapper mapper = sqlSession.getMapper(FinanceMapper.class);
        mapper.updateBonusAndDeduction(employee);
        sqlSession.commit();
        sqlSession.close();
    }
}
